﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NCP.Infrastructure.Common.Specification;
using NCP.Recruiting.Domain.Shared;

namespace NCP.Recruiting.Domain.Aggregates.Jobpositions
{
    public static class JobPositionSpecifications
    {
        public static Specification<JobPosition> GetByStatus(JobPositionStatus jobPositionStatus)
        {
            var status = (int)jobPositionStatus;
            return new DirectSpecification<JobPosition>(x => x.Status == status);
        }

        public static Specification<JobPosition> GetByDeleted(bool deleted)
        {
            return new DirectSpecification<JobPosition>(x => x.Deleted == deleted);
        }

        public static Specification<JobPosition> GetByCompany(Guid companyId)
        {
            return new DirectSpecification<JobPosition>(x => x.CompanyId.Equals(companyId));
        }

        public static Specification<JobPosition> GetByKeyword(String keyword)
        {
            return new DirectSpecification<JobPosition>(x => x.JobTitle.Contains(keyword));
        }

        /// <summary>
        /// 过期的但是状态尚未设置为closed的
        /// </summary>
        /// <returns></returns>
        public static Specification<JobPosition> GetOverdueWithOutClosed()
        {
            var now = DateTime.Now;
            var activeStatus = (int)JobPositionStatus.Active;
            return new DirectSpecification<JobPosition>(x => !x.Deleted &&
                x.Status == activeStatus &&
                x.EndDate < now);
        }
    }
}
